<template>
	<view class="my">
		<view class="top">
			<view class="myinfo">
				<view @click="navMyinfo()">
					<view class="myinfo_name">{{user.realname}}</view>
					<view class="myinfo_aid">AID {{user.aid}}</view>
				</view>
				<view class="photo" @click="navMyinfo()">
					<image :src="user.photo"></image>
				</view>
			</view>
			<view class="qrcode" @click="navMyinfo('/tgqrcode/tgqrcode')">
				<image src="../../static/img/my_qrcode.png"></image>
			</view>
		</view>
		<view class="list">
			<view class="listDetail" v-for="item in myList" @click="myitemNav(item)">
				<view class="listName">
					<image :src="item.icon"></image>
					<text>{{item.text}}</text>
				</view>
				<view class="listText">
					<text>{{item.remark}}</text>
					<image src="../../static/img/my_back.png"></image>
				</view>
			</view>
		</view>
		<view class="exitBtn" @click="exit()">
			<text>退出登录</text>
		</view>
	</view>
</template>

<script>
	import { user,version } from '../../api/index.js'
	export default {
		onLoad() {
			this.init()
		},
		data() {
			return {
				currentToken:'',
				myList: [
					{
						id:'qhsf',
						icon:'../../static/img/my_role.png',
						text:'切换身份',
						remark:'',
						url:'../infosw/infosw'
					},
					{
						id:'wdxj',
						icon:'../../static/img/my_lower.png',
						text:'我的下级',
						remark:'',
						url:'../mylower/mylower'
					},
					{
						id:'kfrx',
						icon:'../../static/img/my_kefu.png',
						text:'客服热线',
						remark:'400-135-2288'
					},
					{
						id:'about',
						icon:'../../static/img/my_version.png',
						text:'关于盟小二',
						remark:''
					},
					{
						id:'swplatform',
						icon:'../../static/img/my_platform.png',
						text:'切换业务平台',
						remark:'超盟U品'
					}
				],
				versionData:{}
			}
		},
		methods: {
			init:function(){
				let that = this;
				this.currentToken = this.$storage('global').getItemSync('loginInfo').token;
				//获取当前版本
				cm.getVersions({
					success:function (res) {
						that.myList[3].remark = res.versions;
						console.log(res.versions)
					},
					fail:(err)=>{
						console.log(err);
					}
				});
				
				this.getVersion();
			},
			navMyinfo:function(url){
				if(!url){
					url = '/myinfo/myinfo';
				}
				uni.navigateTo({
					url: '..'+url
				});
			},
			exit:function(){
				console.log('jumpFunction');
				this.$store.dispatch("global/exitLogin")
			},
			//获取当前版本
			getVersion:function(){
				version().then((res) => {
					console.log(res);
					if(res.code == 0){
						this.versionData = res.data;
					}
				}).catch((e) => {
					console.log(e);
				});
			},
			//列表跳转
			myitemNav:function(item){
				let id = item.id;
				if(id=="kfrx"){ //客服热线
					cm.makePhoneCall({
						phone:item.remark
					});
				}else if(id=="about"){
					const newVersion = this.versionData.version_code.split(".").join('');
					const currentVersion = this.myList[3].remark.split(".").join('');
					if(currentVersion >= newVersion){ //判断当前版本是否是最新版本
						uni.showToast({
							title: "当前版本已是最新版本",
							icon: 'none'
						})
					}else{
						const versionArg = {upLoadOptions:this.versionData.upload_url}; //统一强制更新，不使用热更新
						// if(this.versionData.is_force == 1){
							// versionArg = {upLoadOptions:this.versionData.upload_url};
						// }else{
							// versionArg = {
							// 	upLoadOptions:this.versionData.hotupdate_info
							// };
							// versionArg = {upLoadOptions:this.versionData.upload_url};
						// }
						cm.UpdateInfo(versionArg)  //版本升级
					}
				}else if(id=="swplatform"){
					console.log('jumpTypeChange');
					cm.jumpFunction({
						method:'push',
						url:'/userIdentitySelect',
						data:{},
					});
				}else{
					uni.navigateTo({
						url: item.url
					});
				}
			}
		},
		computed:{
			user(){
				return this.$store.state.global.user
			}
		},
		watch:{
			user(){
				this.init();
			}
		}
	}
</script>

<style lang="scss" scoped>
	.my{
		padding: 28rpx;
		.top{
			padding: 44rpx;
			box-shadow: 0 0rpx 30rpx rgba(0, 0, 0, 0.1);
			border-radius: $uni-border-radius-base;
			.myinfo{
				display: flex;
				width: 100%;
				justify-content: space-between;
				.myinfo_name{
					color: #333333;
					font-weight: 600;
					font-size: $uni-font-size-big;
				}
				.myinfo_aid{
					color: #999999;
					font-size: $uni-font-size-base;
					margin-top: 10rpx;
				}
				.photo{
					image{
						width: 112rpx;
						height: 116rpx;
					}
				}
			}
			.qrcode{
				margin-top: 100rpx;
				image{
					width: 52rpx;
					height: 52rpx;
				}
			}
		}
		
		.list{
			margin-top: 20rpx;
			.listDetail{
				padding: 38rpx 0;
				display: flex;
				justify-content: space-between;
				width: 100%;
				.listName{
					color: #333333;
					font-size: $uni-font-size-lg;
					image{
						width: 44rpx;
						height: 44rpx;
						vertical-align: top;
					}
					text{
						margin-left: 12rpx;
					}
				}
				.listText{
					color: #999999;
					font-size: $uni-font-size-base;
					image{
						width: 36rpx;
						height: 36rpx;
						vertical-align: top;
					}
				}
			}
		}
		.exitBtn{
			margin-top: 20rpx;
			color: #007AFF;
			font-weight: bold;
			font-size: $uni-font-size-lg;
			padding: 10rpx;
			text-align: center;
		}
	}
	
</style>
